package org.meow.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.meow.entity.Visitor;
import org.meow.mapper.VisitorMapper;
import org.meow.service.VisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * &#064;Date: 24/05/16-15:17
 * &#064;Description:
 */
@Service
public class VisitorServiceImpl implements VisitorService {

  @Autowired
  private VisitorMapper visitorsMapper;

  @Override
  public long count() {
    return visitorsMapper.selectCount(null);
  }

  @Override
  public Visitor queryByIp(String ip) {
    LambdaQueryWrapper<Visitor> lambdaQueryWrapper = new LambdaQueryWrapper<Visitor>();
    lambdaQueryWrapper.eq(Visitor::getIpAddress, ip);
    return visitorsMapper.selectOne(lambdaQueryWrapper);
  }

  @Override
  public void save(Visitor visitors) {
    visitorsMapper.insert(visitors);
  }
}
